package com.likou;

import java.util.*;

/**
 * Author: 陈桂明
 * Date: 2025/9/3 15:31
 * Description: q763
 */
public class q763 {
    public static void main(String[] args) {
        q763 q763 = new q763();
        q763.partitionLabels("ababcbacadefegdehijhklij");
    }

    public List<Integer> partitionLabels(String s) {
        List<Integer> ans = new ArrayList<>();

        Map<Character, Integer> map = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            map.put(s.charAt(i), i);
        }

        int max = 0;
        int len = 0;
        for (int i = 0; i < s.length(); i++) {
            len++;
            max = Math.max(max, map.get(s.charAt(i)));
            if (max == i) {
                ans.add(len);
                len = 0;
            }
        }

        return ans;
    }
}
